package com.h3c.tj_nsh.UI.Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.h3c.tj_nsh.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Time: 2016/5/12.
 * Author:Chen  .
 */
public class ITSMAdapter extends RecyclerView.Adapter  {


    @Bind(R.id.iv_itsm_icon)
    ImageView mIvItsmIcon;
    @Bind(R.id.iv_itsm_label)
    TextView mIvItsmLabel;
    private  String[] iconLabers=null;
    private  OnRecyclerViewItemClickListener mOnRecyclerViewItemClickListener;
    public ITSMAdapter(String[] iconLabers ){
        this.iconLabers=iconLabers;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        iconLabers = parent.getResources().getStringArray(R.array.icon_names);
        View view =LayoutInflater.from(parent.getContext()).inflate(R.layout.item_itsm_icon, parent, false);
        return new ViewHolder(view,mOnRecyclerViewItemClickListener);
    }

   public void setOnItemClickListener(OnRecyclerViewItemClickListener listener){
       this.mOnRecyclerViewItemClickListener=listener;
   }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      ViewHolder viewHolder= (ViewHolder) holder;
       // Glide.with(holder.itemView.getContext()).load(image.imageUrl).into(debounceViewHolder.imageIv);
        viewHolder.mIvItsmLabel.setText(iconLabers[position]);

    }


    @Override
    public int getItemCount() {
        return iconLabers == null ? 0 : iconLabers.length;
    }



    static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @Bind(R.id.iv_itsm_icon)
        ImageView mIvItsmIcon;
        @Bind(R.id.iv_itsm_label)
        TextView mIvItsmLabel;
        private OnRecyclerViewItemClickListener mListener=null;

        ViewHolder(View view,OnRecyclerViewItemClickListener listener ) {
            super(view);
            mListener=listener;
            view.setOnClickListener(this);
            int adapterPosition = getAdapterPosition();
            ButterKnife.bind(this, view);
        }

        @Override
        public void onClick(View v) {
            if(mListener!=null){
                mListener.onItemClick(v,getAdapterPosition());
            }
        }
    }

    public static interface OnRecyclerViewItemClickListener{
        void onItemClick(View view,int postion);
    }

}
